<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class AgentInitializationSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $agentArr = [
            [
                'name' => '大咖1',
                'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                'phone' => 18000000028,
                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                'children' => [
                    [
                        'name' => '大咖2',
                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                        'phone' => 18000000029,
                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                        'children' => [
                            [
                                'name' => '大咖3',
                                'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                'phone' => 18000000001,
                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                'children' => [
                                    [
                                        'name' => '精英1',
                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                        'phone' => 18000000002,
                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                        'children' => [
                                            [
                                                'name' => '大咖4',
                                                'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                'phone' => 18000000004,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖6',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000010,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英4',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000011,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主4',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000012,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                ]
                                            ],
                                            [
                                                'name' => '精英2',
                                                'level' => \App\Models\Agent::LEVEL_ELITE,
                                                'phone' => 18000000005,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖7',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000013,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英5',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000014,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主5',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000015,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                ]
                                            ],
                                            [
                                                'name' => '群主2',
                                                'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                'phone' => 18000000006,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖8',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000016,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英6',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000017,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主6',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000018,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                ]
                                            ],
                                        ]
                                    ],
                                    [
                                        'name' => '群主1',
                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                        'phone' => 18000000003,
                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                        'children' => [
                                            [
                                                'name' => '大咖5',
                                                'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                'phone' => 18000000007,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖9',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000019,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英7',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000020,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主7',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000021,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                ]
                                            ],
                                            [
                                                'name' => '精英3',
                                                'level' => \App\Models\Agent::LEVEL_ELITE,
                                                'phone' => 18000000008,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖10',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000022,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英8',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000023,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主8',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000024,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],

                                                ]
                                            ],
                                            [
                                                'name' => '群主3',
                                                'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                'phone' => 18000000009,
                                                'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                'children' => [
                                                    [
                                                        'name' => '大咖11',
                                                        'level' => \App\Models\Agent::LEVEL_STRONGMAN,
                                                        'phone' => 18000000025,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '精英9',
                                                        'level' => \App\Models\Agent::LEVEL_ELITE,
                                                        'phone' => 18000000026,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                    [
                                                        'name' => '群主9',
                                                        'level' => \App\Models\Agent::LEVEL_GROUP_OWNER,
                                                        'phone' => 18000000027,
                                                        'invitation_code' => \App\Models\Agent::generateInvitationCode(),
                                                    ],
                                                ]
                                            ],
                                        ]
                                    ],
                                ]
                            ],
                        ]
                    ],
                ]
            ]
        ];

        $pwd = '$2y$10$hlXlrr5TVkf1.jvRWfwt5e.c9s8knXvY2Vg9W4Qie.o7jahW9hz2e';
        $fun = function ($agentArr, $directInvitor, $indirectInvitor) use (&$fun, $pwd) {
            foreach ($agentArr as $item) {
                $agent = \App\Models\Agent::query()->create(array_merge(
                    \Illuminate\Support\Arr::only($item, ['name', 'phone', 'level', 'invitation_code']),
                    [
                        'password' => $pwd,
                        'direct_inviter' => $directInvitor['id'] ?? 0,
                        'indirect_inviter' => $indirectInvitor['id'] ?? 0
                    ]
                ));

                if (isset($item['children'])) {
                    $fun($item['children'], $agent, $directInvitor);
                }
            }
        };

        $fun($agentArr, null, null);
    }
}
